| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 'use server';
- import View from './view';
- import { notFound, forbidden, redirect } from 'next/navigation';
- import { BoardLayout } from '@/constants/forum';
- import { isAuthenticated } from '@/lib/api/auth';
- import { fetchBoard } from '@/lib/api/forum/board';
- import { fetchPostData } from '@/lib/api/forum/post';
- export default async function PostView({ params }: { params: Promise<{ id: string }> })
- {
- const { id } = await params;
- if (!/^\d+$/.test(id)) {
- return forbidden();
- }
- // 게시글 정보 조회
- const post = await fetchPostData(Number(id));
- if (!post.success || !post.data) {
- return notFound();
- }
- // 게시판 조회
- const board = await fetchBoard(post.data.boardCode);
- if (!board || !board.data) {
- return notFound();
- }
- if (!board.data.isActive) {
- return forbidden();
- }
- const boardMeta = board.data.boardMeta;
- // 1:1 게시판은 로그인한 사용자만 접근 가능
- if (boardMeta.list.layout === BoardLayout.QnA && !await isAuthenticated()) {
- redirect('/login');
- }
- return (
- <View _board={board.data} _post={post.data} />
- );
- }
|